import { _decorator, Component, Input, Node, type EventTouch, EventTarget } from 'cc'
import { Logger, ServiceLocator } from '../utils'
import { FrameEvents, ServiceName } from '../../enum'
const { ccclass, property } = _decorator

@ccclass('TouchBorad')
export class TouchBorad extends Component {
    #logger = new Logger('触摸面板')
    #service = ServiceLocator;

    get events() {
        return this.#service.get<EventTarget>(ServiceName.Event)
    }

    protected onLoad(): void {
        this.node.on(Input.EventType.TOUCH_END, this.onTouchEnd, this)
    }

    protected onDestroy(): void {
        this.node.off(Input.EventType.TOUCH_END, this.onTouchEnd, this)
    }


    onTouchEnd(event: EventTouch) {
        this.#logger.debug('触摸面板', event.getLocation(), event.getUILocation())
        this.events.emit(FrameEvents.stepNext)
    }


}


